package com.yixiu.study.juc.taobao.num3;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;

/**
 * @CalssName T06_BlockingQueue
 * @Description
 * @Author yixiu
 * @Date 2021/6/29 10:21
 * @Verison 1.0
 **/
public class T06_BlockingQueue {

    static BlockingQueue<String> q1 = new ArrayBlockingQueue<>(1);
    static BlockingQueue<String> q2 = new ArrayBlockingQueue<>(1);

    public static void main(String[] args) {
        char[] aI = "1234567".toCharArray();
        char[] aC = "ABCDEFG".toCharArray();

        new Thread(() -> {
            for(char c: aI){
                System.out.println(c);

                try {
                    q1.put("ok");
                    q2.take();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }, "t1").start();

        new Thread(() -> {
            for(char c: aC){
                try {
                    q1.take();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

                System.out.println(c);

                try {
                    q2.put("ok");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }, "t2").start();

    }

}
